using System.Web.Mvc;
using Tools.Common.Reflection;
using Web.App.Infrastructure.Extensions;
using Web.App.Infrastructure.Interface;
using Webshop20.Interface.MVC.Controllers;

namespace Webshop20.Interface.MVC.Filters
{
    public class IsAuthorizedAttribute : ActionFilterAttribute 
    {
        public string ControllerName { get; set; }
        public string ControllerAction { get; set; }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
           if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
                    filterContext.HttpContext
                    .Response
                    .Redirect(string.Format("~/Login?ControllerName={0}&ControllerAction={1}",
                                                                              ControllerName ?? typeof(HomeController).Name,
                                                                              ControllerAction ?? ReflectAbout<HomeController>.GetProperty(x=>x.Index()).Name ));
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            throw new System.NotImplementedException();
        }
    }
}